package com.qf.cosmetology.controller;

import com.qf.cosmetology.entity.Subject;
import com.qf.cosmetology.result.ResponseCode;
import com.qf.cosmetology.result.ResponseData;
import com.qf.cosmetology.service.SubjectService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-06-25 16:17:07
 */
@RestController
@RequestMapping("subjects")
public class SubjectController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectService subjectService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "queryById",notes = "通过项目Id获取项目详情信息")
    @ApiImplicitParam(name = "id",value = "项目id",dataType = "int")
    @GetMapping("/{id}")
    public ResponseData queryById(@PathVariable Integer id) {
        Subject subject = this.subjectService.queryById(id);
        return new ResponseData(ResponseCode.SUCCESS,subject);
    }

    @CrossOrigin
    @ApiOperation(value = "queryByTitle",notes = "通过项目名称获取项目列表")
    @ApiImplicitParam(name = "title",value = "项目名称")
    @GetMapping("/type/{title}")
    public ResponseData queryByTitle(@PathVariable String title) {
        return this.subjectService.queryByTitle(title);
    }

    @ApiOperation(value = "getAllSubjectCount",notes = "获取所有项目总数")
    @GetMapping("/count")
    public ResponseData getAllSubjectCount() {
        return this.subjectService.getAllSubjectCount();
    }

}
